﻿using MotorLibrary.DAL;
using MotorLibrary.Error;
using MotorLibrary.Repository;
using MotorLibrary.Repository.DTO;
using MotorLibrary.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

namespace WebMotor.Controllers
{
    public class VariableController: ApiController, WebMotor.Controllers.IVariableController
    {
        private IVariableService _variableService;

        public VariableController(IVariableService variableService)
        {
            this._variableService = variableService;
        }


        [HttpGet]
        [Route("api/variable/{id}")]
        public VariableDTO Get(long id)
        {
            return _variableService.Read(id);
        }

        [HttpGet]
        [Route("api/variable")]
        public IList<VariableDTO> List()
        {
            return _variableService.List();
        }

        [HttpPost]
        [Route("api/variable")]
        public VariableDTO Post(VariableDTO dto)
        {
            return _variableService.Create(dto);
        }

        [HttpPut]
        [Route("api/variable")]
        public VariableDTO Put(VariableDTO dto)
        {
            return _variableService.Update(dto);
        }

        [HttpDelete]
        [Route("api/variable/{id}")]
        public VariableDTO Delete(long id)
        {
            return _variableService.Delete(id);
        }

        [HttpGet]
        [Route("api/variable/endpoint/{EndpointID}")]
        public IList<VariableDTO> FilterByEndpoint(long EndpointID)
        {
            return _variableService.FilterByEndpoint(EndpointID);
        }
    }
}